package player

import (
	. "game_server/logic/internal"
	"game_server/model"
	"proto/player"
)

type playerService struct {
}

func init() {
	Service.Register(new(playerService))
}

func (*playerService) Name() string {
	return "proto_player"
}

func (*playerService) SyncData(player *model.Player, request *proto_player.SyncData) (err error) {
	detail := player.Detail
	response := new(proto_player.SyncData)
	response.Name = detail.Name
	response.Level = uint32(detail.Level)
	response.Exp = detail.Exp

	rpc.SyncData(player, response)

	return
}

func (*playerService) TestSetLevel(player *model.Player, request *proto_player.TestSetLevel) (err error) {
	system.SetLevel(player, uint16(request.Level))

	response := new(proto_player.OnTestSetLevel)
	rpc.OnTestSetLevel(player, response)

	return
}

func (*playerService) TestSetName(player *model.Player, request *proto_player.TestSetName) (err error) {
	system.setName(player, request.Name)

	response := new(proto_player.OnTestSetName)
	rpc.OnTestSetName(player, response)

	return
}
